package com.ham.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import org.apache.commons.lang.StringUtils;

public class MenuItemDTO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7934484744505196485L;
	private String linkName;
	private String linkParam;
	private String title;
	private String code;
	private int permission;
	private List<MenuItemDTO> children;

	public String getLinkName() {
		return linkName;
	}

	public void setLinkName(String linkName) {
		this.linkName = linkName;
	}

	public String getLinkParam() {
		return linkParam;
	}

	public void setLinkParam(String linkParam) {
		this.linkParam = linkParam;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getPermission() {
		return permission;
	}

	public void setPermission(int permission) {
		this.permission = permission;
	}

	public List<MenuItemDTO> getChildren() {
		if (children == null) {
			children = new ArrayList<MenuItemDTO>();
		}
		return children;
	}

	public void setChildren(List<MenuItemDTO> children) {
		this.children = children;
	}

	public Map<String, String> extractParam() {
		Map<String, String> result = new HashMap<String, String>();
		if (StringUtils.isNotEmpty(linkParam)) {
			final StringTokenizer tokenizer = new StringTokenizer(linkParam,
					"&");
			while (tokenizer.hasMoreTokens()) {
				String token = tokenizer.nextToken();
				String[] s = token.split("\\=");
				result.put(s[0], s[1]);
			}
		}
		return result;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

}